/*    */ package com.zimbra.cs.service.admin;
/*    */ 
/*    */ import com.zimbra.common.account.Key.DomainBy;
/*    */ import com.zimbra.common.service.ServiceException;
/*    */ import com.zimbra.common.soap.AdminConstants;
/*    */ import com.zimbra.common.soap.Element;
/*    */ import com.zimbra.cs.account.Account;
/*    */ import com.zimbra.cs.account.AccountServiceException;
/*    */ import com.zimbra.cs.account.Domain;
/*    */ import com.zimbra.cs.account.Provisioning;
/*    */ import com.zimbra.cs.account.accesscontrol.AdminRight;
/*    */ import com.zimbra.cs.account.accesscontrol.Rights.Admin;
/*    */ import com.zimbra.soap.JaxbUtil;
/*    */ import com.zimbra.soap.ZimbraSoapContext;
/*    */ import com.zimbra.soap.admin.message.AutoProvAccountRequest;
/*    */ import com.zimbra.soap.admin.type.DomainSelector;
/*    */ import com.zimbra.soap.admin.type.DomainSelector.DomainBy;
/*    */ import com.zimbra.soap.admin.type.PrincipalSelector;
/*    */ import com.zimbra.soap.type.AutoProvPrincipalBy;
/*    */ import java.util.List;
/*    */ import java.util.Map;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ public class AutoProvAccount
/*    */   extends AdminDocumentHandler
/*    */ {
/*    */   public boolean defendsAgainstDelegateAdminAccountHarvesting()
/*    */   {
/* 44 */     return true;
/*    */   }
/*    */   
/*    */   public Element handle(Element request, Map<String, Object> context) throws ServiceException
/*    */   {
/* 49 */     ZimbraSoapContext zsc = getZimbraSoapContext(context);
/* 50 */     Provisioning prov = Provisioning.getInstance();
/*    */     
/* 52 */     AutoProvAccountRequest req = (AutoProvAccountRequest)JaxbUtil.elementToJaxb(request);
/* 53 */     Key.DomainBy domainBy = req.getDomain().getBy().toKeyDomainBy();
/* 54 */     String domainKey = req.getDomain().getKey();
/* 55 */     Domain domain = prov.get(domainBy, domainKey);
/* 56 */     if (domain == null) {
/* 57 */       throw AccountServiceException.NO_SUCH_DOMAIN(domainKey);
/*    */     }
/*    */     
/* 60 */     checkRight(zsc, context, domain, Rights.Admin.R_autoProvisionAccount);
/*    */     
/* 62 */     AutoProvPrincipalBy by = req.getPrincipal().getBy();
/* 63 */     String principal = req.getPrincipal().getKey();
/*    */     
/* 65 */     String password = req.getPassword();
/*    */     
/* 67 */     Account acct = prov.autoProvAccountManual(domain, by, principal, password);
/* 68 */     if (acct == null) {
/* 69 */       throw ServiceException.FAILURE("unable to auto provision account: " + principal, null);
/*    */     }
/*    */     
/* 72 */     Element response = zsc.createElement(AdminConstants.AUTO_PROV_ACCOUNT_RESPONSE);
/* 73 */     ToXML.encodeAccount(response, acct);
/* 74 */     return response;
/*    */   }
/*    */   
/*    */   public void docRights(List<AdminRight> relatedRights, List<String> notes)
/*    */   {
/* 79 */     relatedRights.add(Rights.Admin.R_autoProvisionAccount);
/*    */   }
/*    */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/admin/AutoProvAccount.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */